package com.loan.controller.app.over;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSONObject;
import com.loan.common.annotation.Log;
import com.loan.common.core.controller.BaseController;
import com.loan.common.core.domain.PageQuery;
import com.loan.common.core.domain.Result;
import com.loan.common.core.domain.entity.SysUser;
import com.loan.common.core.page.TableDataInfo;
import com.loan.common.enums.BusinessType;
import com.loan.system.domain.OverConfigEntity;
import com.loan.system.domain.OverWeightEntity;
import com.loan.system.domain.PayBankEntity;
import com.loan.system.service.OverConfigService;
import com.loan.system.service.PayBankService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author shiguang
 * @date 2022年09月26日 20:53
 */
@Validated
@Api(value = "催收配置管理", tags = {"催收配置管理"})
@RequiredArgsConstructor
@RestController
@RequestMapping("/system/app/over")
public class OverConfigController extends BaseController {

    private final OverConfigService overConfigService;

    /**
     * 获取列表
     */
    @ApiOperation("获取列表")
    @GetMapping("/page")
    public TableDataInfo<OverConfigEntity> list(OverConfigEntity entity, PageQuery pageQuery) {
        return overConfigService.selectPageList(entity, pageQuery);
    }

    /**
     * 根据id查询详情
     */
    @ApiOperation("根据id查询详情")
    @GetMapping(value = {"/{id}"})
    public Result<OverConfigEntity> getInfo(@ApiParam("ID") @PathVariable(value = "id", required = false) Long id) {
        if (ObjectUtil.isNotNull(id)) {
            return Result.ok(overConfigService.selectById(id));
        }
        return Result.ok();
    }

    /**
     * 新增催收配置
     */
    @ApiOperation("新增催收配置")
    @Log(title = "新增催收配置", businessType = BusinessType.INSERT)
    @PostMapping
    public Result<Void> add(@Validated @RequestBody OverConfigEntity entity) {
        return toAjax(overConfigService.add(entity));
    }

    /**
     * 修改催收配置
     */
    @ApiOperation("修改催收配置")
    @Log(title = "修改催收配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result<Void> update(@Validated @RequestBody OverConfigEntity entity) {
        return toAjax(overConfigService.update(entity));
    }

    /**
     * 删除催收配置
     */
    @ApiOperation("删除催收配置")
    @Log(title = "删除催收配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{id}")
    public Result<Void> remove(@ApiParam("ID") @PathVariable("id") Long id) {
        return toAjax(overConfigService.delete(id));
    }

    @ApiOperation("根据id查询详情")
    @GetMapping(value = {"/getUserIds"})
    public Result<List<Long>> getUserIdsById(@RequestParam Long id) {
        return Result.ok(overConfigService.getUserIdsById(id));
    }

    @ApiOperation("修改催收绑定用户")
    @Log(title = "修改催收绑定用户", businessType = BusinessType.UPDATE)
    @PostMapping("/updateOverUserIds")
    public Result<Void> updateOverUserIds(@RequestBody JSONObject jsonObject) {
        return toAjax(overConfigService.updateOverUserIds(jsonObject));
    }

    @ApiOperation("获取催收员")
    @GetMapping(value = {"/userList"})
    public Result<List<SysUser>> getListOverUserIds(String beginTime, String endTime){
        return Result.ok(overConfigService.getListOverUserIds(beginTime,endTime));
    }

    @ApiOperation("催收配置获取催收员列表")
    @GetMapping(value = {"/getOverUserList"})
    public Result<List<SysUser>> getOverUserList(long id){
        return Result.ok(overConfigService.getOverUserList(id));
    }

}
